show_scatter()
The {detourr} package consists of two very similar
scatterplot displays; there’s a 2D variant and a 3D variant, and both are
produced using the show_scatter() display method. Both of
these have similar capabilities for user interaction, including point
selection, brushing, orbit controls and more. In this vignette, we’ll go
through each of these in turn and describe how they can be used and
configured.
For the following examples, the pdfsense dataset will be
used. (Wang et al. 2018),
(Cook, Laa, and Valencia 2018).
library(detourr)
library(dplyr)
data(pdfsense)
pcs <- pdfsense %>%
select(X1:X56) %>%
prcomp()
pcs <- scale(pcs$x) %>%
as.data.frame() %>%
select(PC1:PC6)
plot_data <- pdfsense %>%
select(-(X1:X56)) %>%
mutate(Type = as.character(Type)) %>%
bind_cols(pcs)
All of the interactivity described in this vignette can be demonstrated in these two examples.
Below is the 2D variant of show_scatter():
set.seed(1)
animate_tour(
plot_data,
grand_tour(2),
show_scatter(tour_aes(
colour = Type,
label = I(ID)
),
axes = FALSE,
size = 0.5
)
)
And the 3D variant:
set.seed(1)
animate_tour(
plot_data,
grand_tour(3),
show_scatter(tour_aes(
colour = Type,
label = c(InFit, Type, ID, pt, x, mu)
),
axes = FALSE,
size = 0.5
)
)
In the above example, labels are defined within the call to
tour_aes, which contains all of the aesthetic mappings for
the tour. The label aesthetic produces a tooltip which is
shown whenever the mouse is hovered over the data point:
By default, the text in the tooltip will have the format
column_name: value, with each specified column on a new
line. If you want more control over what appears in the tooltip, you can
use the I() function so that the values in the aesthetic
column appear as-is. For example in the
2D scatter plot example, the
ID column is specified as-is by using
tour_aes(label = I(ID)):
When using the I() function for the label aesthetic, only
one column can be specified at a time. To split text in the tooltip over
multiple line, you will need to use <br> as the line
break instead of \n.
The following is a brief breakdown of the controls found on the left side of the visual. Note that the icon for the currently selected control will be highligted blue; otherwise it will be black.
| Control | Icon | Description |
|---|---|---|
| Orbit |
|
When the show_scatter() widget is generated, orbit
controls will be enabled by default. This allows click and drag to
rotate the visual, and scrolling to zoom. Note that orbit controls
for the 2D variant work best if dragging from left to right, not
up and down. Also note that the icon for the currently selected
control will be highligted blue; otherwise it will be black.
|
| Pan |
|
The pan control also allows scrolling to zoom, and click and drag to pan. |
| Box Selection |
|
The selection control allows for box selection by clicking and
dragging. Holding the shift key will allow for
multiple selection, and points outside of the selection will be
indicated by increased transparancy. There is currently a
limitation where only visible points can be selected. If a point
is completely obscured by other points, it will not be selected.
|
| Brush |
|
The brush button will apply the current colour to the selected points. |
| Colour Selector |
|
The colour selector will look slightly different depending on the browser being used. When the colour selection is changed, the selected points will be updated immediately. |
Below is an example of using the box selection control, brush control, and colour selector together:
The timeline at the bottom of the widget controls play and pause, and allows for scrubbing to a specific point in the tour. The timeline can also be used to jump to a specific basis by clicking on any of the white basis markers, and hovering the mouse over the basis markers will display the index of that basis.
This funcionality is shown below:
In this vignette we’ve demonstrated the interactivity of the
show_scatter() display method in the {detourr} package. If
you have any issues or suggestions, please open an issue on
github.